#include <iostream>
#include <fstream>
#include <cassert>
#include <list>
#include <vector>

using namespace std;

#include "cgal_helper.h"
#include "ConvexHull.h"
#include "DiamondTest.h"
#include "Face.h"
#include "Triangulation.h"

void test(vector<Point>p_list);

int
main (int argc, char *argv[]) {
  vector<Point> p_list;
  
  if (argc != 2) {
    cout << "Usage: ./main [File Name]";
  }

  string line;
  ifstream p_file(argv [1]);
  cout.precision(12);
  if (p_file.is_open()) {
    while (p_file.good()) {
      getline (p_file, line);
      if (line.length() != 0) {
        vector<double> coords  = StringUtils::getCoords(line);
        Point p(coords [0], coords [1], coords [2]);
        p_list.push_back(p);
      } else {
        break;
      }
    }
    p_file.close();
  }
	else {
		cout<< "unable to open file"<<endl;
  }
  Triangulation ct(p_list);
  ct.run();
	
  //cout << "Possible Edges: " << ct.diamond_test().size() << endl;

  return 0;
}

/*
void test(vector<Point> p_list) {

  Delaunay dt(p_list.begin(), p_list.end());
  FT wt = 0.0;

  for (Finite_edges_iterator it = dt.finite_edges_begin(); it != dt.finite_edges_end(); it++) {
    wt  += dt.segment(*it).squared_length();
  }

  cout << "Input Vertices: " << p_list.size() << endl;
  cout << "Triangulation Valid: " << (dt.is_valid(false)? "yes": "no") << endl;
  cout << "Number of Vertices in Triangulation: " << dt.number_of_vertices() << endl;
  cout << "Number of edges: " << dt.number_of_edges() << endl;
  cout << "Number of finite edges: " << dt.number_of_finite_edges() << endl;
  cout << "Number of finite cells: " << dt.number_of_finite_cells() << endl;
  cout << "Number of finite facets: " << dt.number_of_finite_facets() << endl;
  cout << "Squared weight of Triangulation: " << wt << endl;
  ConvexHull hull(p_list);
  Polyhedron p  = hull.run();
  cout << "Convex Hull" << endl;
  cout << "Number of Vertices: " << p.size_of_vertices() << endl;
  cout << "Number of Faces: " << p.size_of_facets() << endl;
  Triangulation t = Triangulation(p_list);
  t.run();
  Point p1  = Point(1,0,0);
  Point p2  = Point(0,1,0);
  Point p3  = Point(1,1,0);
  DiamondTest dtest(p1, p2, p3);
  dtest.testPoint(Point(1,1,-1));
  cout << dtest.getOrientation(Point(1,1,-1));
  cout << dtest.getOrientation(Point(0,0,1));
}*/
